import { BehaviorSubject, Observable } from 'rxjs'

export class ObservableStore<T> {
  value$: Observable<T>
  private _value$: BehaviorSubject<T>

  constructor(initialValue: T) {
    this._value$ = new BehaviorSubject(initialValue)
    this.value$ = this._value$.asObservable()
  }

  get value(): T {
    return this._value$.getValue()
  }

  setValue(nextValue: T): void {
    this._value$.next(nextValue)
  }
}
